import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;

public class Transform {

    /**
     * Performes an XSLT transformation, sending the results
     * to System.out.
     */
    public static void main(String[] args) throws Exception {

//        File xmlFile = new File("schedule.xml");
//        File xsltFile = new File("schedule.xslt");
//
//        Source xmlSource = new StreamSource(xmlFile);
//        Source xsltSource = new StreamSource(xsltFile);
//
//        TransformerFactory transFact =
//                TransformerFactory.newInstance();
//        Transformer trans = transFact.newTransformer(xsltSource);
//
//        trans.transform(xmlSource, new StreamResult(System.out));
//        
//
//        File xmlFile = new File("users.xml");
//        File xsltFile = new File("users.xsl");

        File xmlFile = new File("fordynamic.xml");
        File xsltFile = new File("dynamichtmlform.xsl");
		Source srcXml = new StreamSource(xmlFile);
		Source srcXsl = new StreamSource(xsltFile);
		StringWriter writer = new StringWriter();
		Result result = new StreamResult(writer);
		
		TransformerFactory tFactory = TransformerFactory.newInstance();
		Transformer transformer = tFactory.newTransformer(srcXsl);

		transformer.transform(srcXml, result);

		System.out.println(writer.toString());
    }
}